package org.testis.gui.mvc.view.testdesign;

import org.testis.gui.mvc.view.*;
import org.testis.gui.mvc.controller.TestDesignControllerList;
import org.testis.gui.mvc.controller.testdesign.ConditionsController;
import org.testis.gui.mvc.utilities.Validatable;
import org.testis.gui.mvc.controller.testdesign.TestStepController;
import org.testis.gui.mvc.utilities.AtofEntryItem;
import org.testis.gui.mvc.utilities.ValidationUtils;
import org.testis.gui.mvc.view.labels.LabelPairSettingsView;
import org.testis.orm.refinedclasses.PostConditionCaseRefined;
import org.testis.orm.refinedclasses.PreConditionCaseRefined;
import org.testis.orm.refinedclasses.TestDesignTreeNode;
import org.testis.orm.testbed.refined.DutRefined;
import org.testis.orm.testbed.refined.NetworkAdapterRefined;
import org.testis.orm.testbed.refined.TestPcRefined;
import java.awt.Frame;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import org.orm.PersistentException;

/**
 *
 * @author  Cahit Emir Erel
 */
public class TestStepView extends AtofBaseDialog implements
        AbstractViewPanel, Validatable {

    private static final long serialVersionUID = 2039834L;
    private boolean m_editMode;
    private String[] m_choices;
    private String m_windowTitle;
    private TestDesignTreeNode m_selectedNode;
    HashMap<Integer, String> hTestPcs;
    HashMap<Integer, String> hDuts;
    HashMap<Integer, String> hNetworkAdapters;
    Integer curPcId = 0;
    private LabelPairSettingsView m_labelSettingsView;

    public TestStepView(Frame parent,
            boolean modal,
            boolean editMode) {
        super(parent, modal);
        m_editMode = editMode;
        m_selectedNode = TestDesignControllerList.newInstance().getTreeController().getSelectedTreeNode();
        if (m_selectedNode.hasChildren()) {
            System.out.println(m_selectedNode.getName() + " has children");
        } else {
            System.out.println(m_selectedNode.getName() + " has no children");
        }

        if (editMode) {
            m_windowTitle = "Edit Test Step";
        } else {
            m_windowTitle = "Add Test Step";
        }
        m_labelSettingsView = new LabelPairSettingsView();
        initComponents();
        cmbPcList.removeAllItems();
        cmbDeviceList.removeAllItems();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        nameLabel = new javax.swing.JLabel();
        descriptionLabel = new javax.swing.JLabel();
        descriptionTextField = new javax.swing.JTextField();
        modulTypeLabel = new javax.swing.JLabel();
        modulTypeChoice = new java.awt.Choice();
        actionLabel = new javax.swing.JLabel();
        actionChoice = new java.awt.Choice();
        timeoutLabel = new javax.swing.JLabel();
        timeoutTextField = new javax.swing.JTextField();
        noOfRetryOnFailLabel = new javax.swing.JLabel();
        noOfRetryOnFailTextField = new javax.swing.JTextField();
        nameTextField = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        pcLabel = new javax.swing.JLabel();
        label1 = new java.awt.Label();
        dutLabel = new javax.swing.JLabel();
        browserSpeedLabel = new javax.swing.JLabel();
        browserSpeedSpinner = new JSpinner(new SpinnerNumberModel(600, //initial value
            100, //min
            2000, //max
            50));
    browserTypeLabel = new javax.swing.JLabel();
    browserTypeChoice = new java.awt.Choice();
    cmbPcList = new javax.swing.JComboBox();
    cmbDeviceList = new javax.swing.JComboBox();
    txtDutIp = new javax.swing.JTextField();
    jPanel5 = new javax.swing.JPanel();
    dataArrayAppliesToCaseLabel = new javax.swing.JLabel();
    dataArrayAppliesToCaseChoice = new java.awt.Choice();
    successPercentageLabel = new javax.swing.JLabel();
    successPercentageSpinner = new JSpinner(new SpinnerNumberModel(100, //initial value
        0, //min
        100, //max
        1));
btnSuccessPercentageHelp = new javax.swing.JButton();
delayTimeLabel = new javax.swing.JLabel();
delayTimeTextField = new javax.swing.JTextField();
aSynchCallLabel = new javax.swing.JLabel();
aSynchCallChoice = new java.awt.Choice();
criticalLabel = new javax.swing.JLabel();
criticalChoice = new java.awt.Choice();
delayTimeLabel1 = new javax.swing.JLabel();
afterdelayTimeTextField = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
txtStoreResultPostfix = new javax.swing.JTextField();
labelSettingsScrollPane = new javax.swing.JScrollPane();
labelSettingsScrollPane.setViewportView(m_labelSettingsView);
jPanel8 = new javax.swing.JPanel();
supportedDeviceGroupLabel = new javax.swing.JLabel();
supportedDeviceGroupChoice = new java.awt.Choice();
saveButton = new javax.swing.JButton();
btnEditLabels = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(m_windowTitle);
setModal(true);
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosed(java.awt.event.WindowEvent evt) {
        formWindowClosed(evt);
    }
    });

    nameLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    nameLabel.setText("Name * :");

    descriptionLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    descriptionLabel.setText("Description:");

    descriptionTextField.setFont(new java.awt.Font("Dialog", 0, 11));
    descriptionTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            descriptionTextFieldActionPerformed(evt);
        }
    });
    descriptionTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            descriptionTextFieldFocusLost(evt);
        }
    });

    modulTypeLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    modulTypeLabel.setText("Module Type * :");

    modulTypeChoice.add("");
    if (m_editMode && m_selectedNode.hasChildren()) {
        modulTypeChoice.setEnabled(false);
    } else {
        m_choices = TestDesignControllerList.newInstance().getTestStepController().operationGetModulTypeList();
        for (int i=0;i<m_choices.length;i++) {
            modulTypeChoice.add(m_choices[i]);
        }
        m_choices=null;
    }
    modulTypeChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            modulTypeChoiceItemStateChanged(evt);
        }
    });

    actionLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    actionLabel.setText("Action * :");

    actionChoice.setEnabled(false);
    actionChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            actionChoiceItemStateChanged(evt);
        }
    });

    timeoutLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    timeoutLabel.setText("Timeout * :");

    timeoutTextField.setFont(new java.awt.Font("Dialog", 0, 11));
    timeoutTextField.setText("120");
    timeoutTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            timeoutTextFieldActionPerformed(evt);
        }
    });
    timeoutTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            timeoutTextFieldFocusLost(evt);
        }
    });

    noOfRetryOnFailLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    noOfRetryOnFailLabel.setText("No of Retry on Fail:");

    noOfRetryOnFailTextField.setFont(new java.awt.Font("Dialog", 0, 11));
    noOfRetryOnFailTextField.setText("1");
    noOfRetryOnFailTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            noOfRetryOnFailTextFieldActionPerformed(evt);
        }
    });
    noOfRetryOnFailTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            noOfRetryOnFailTextFieldFocusLost(evt);
        }
    });

    nameTextField.setFont(new java.awt.Font("Dialog", 0, 11));
    nameTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            nameTextFieldActionPerformed(evt);
        }
    });
    nameTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            nameTextFieldFocusLost(evt);
        }
    });

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(nameLabel)
                .addComponent(modulTypeLabel)
                .addComponent(timeoutLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(noOfRetryOnFailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(actionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(nameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
                .addComponent(descriptionTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
                .addComponent(modulTypeChoice, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
                .addComponent(actionChoice, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
                .addComponent(noOfRetryOnFailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(timeoutTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );

    jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {actionLabel, descriptionLabel, modulTypeLabel, nameLabel});

    jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {noOfRetryOnFailTextField, timeoutTextField});

    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(nameLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(descriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(descriptionLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(modulTypeLabel)
                .addComponent(modulTypeChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(actionLabel)
                .addComponent(actionChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(noOfRetryOnFailLabel)
                .addComponent(noOfRetryOnFailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(timeoutLabel)
                .addComponent(timeoutTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap(68, Short.MAX_VALUE))
    );

    jTabbedPane1.addTab("General", jPanel1);

    pcLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    pcLabel.setText("PC * :");

    label1.setFont(new java.awt.Font("Dialog", 0, 11));
    label1.setText("Dut Ip:");

    dutLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    dutLabel.setText("<--->");

    browserSpeedLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    browserSpeedLabel.setText("Browser Speed * :");

    // yalnizca webautomation moduleda enabled
    browserSpeedSpinner.setEnabled(false);
    browserSpeedSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            browserSpeedSpinnerStateChanged(evt);
        }
    });

    browserTypeLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    browserTypeLabel.setText("Browser Type * :");

    browserTypeChoice.setEnabled(false);
    browserTypeChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            browserTypeChoiceItemStateChanged(evt);
        }
    });

    cmbPcList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
    cmbPcList.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            cmbPcListİtemStateChanged(evt);
        }
    });

    cmbDeviceList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
    cmbDeviceList.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            cmbDeviceListİtemStateChanged(evt);
        }
    });

    javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
    jPanel6.setLayout(jPanel6Layout);
    jPanel6Layout.setHorizontalGroup(
        jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel6Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(label1, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                .addComponent(dutLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                .addComponent(pcLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(txtDutIp)
                .addComponent(cmbDeviceList, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(cmbPcList, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel6Layout.createSequentialGroup()
                    .addComponent(browserTypeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(browserTypeChoice, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
                .addGroup(jPanel6Layout.createSequentialGroup()
                    .addComponent(browserSpeedLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(browserSpeedSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)))
            .addGap(109, 109, 109))
    );

    jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {browserSpeedLabel, browserTypeLabel, dutLabel, label1, pcLabel});

    jPanel6Layout.setVerticalGroup(
        jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel6Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(browserTypeChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel6Layout.createSequentialGroup()
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(pcLabel)
                        .addComponent(cmbPcList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(browserTypeLabel))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(dutLabel)
                        .addComponent(cmbDeviceList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(browserSpeedLabel)
                        .addComponent(browserSpeedSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(9, 9, 9)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtDutIp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addGap(219, 219, 219))
    );

    jTabbedPane1.addTab("Run-time parameters", jPanel6);

    dataArrayAppliesToCaseLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    dataArrayAppliesToCaseLabel.setText("DataArray Applies to Case * :");

    TestDesignTreeNode parent = TestDesignControllerList.newInstance().getTreeController().getSelectedTreeNode();
    if (!(parent.getObject() instanceof PreConditionCaseRefined || parent.getObject() instanceof PostConditionCaseRefined)) {
        dataArrayAppliesToCaseChoice.add("false");
        dataArrayAppliesToCaseChoice.add("true");
    } else {
        dataArrayAppliesToCaseChoice.setEnabled(false);
    }
    dataArrayAppliesToCaseChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            dataArrayAppliesToCaseChoiceItemStateChanged(evt);
        }
    });

    successPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    successPercentageLabel.setText("Success Percentage * :");

    if (parent.getObject() instanceof PreConditionCaseRefined || parent.getObject() instanceof PostConditionCaseRefined) {
        SpinnerNumberModel temp = (SpinnerNumberModel)successPercentageSpinner.getModel();
        temp.setStepSize(0);
        //successPercentageSpinner = new JSpinner(new SpinnerNumberModel(100, 100, 100, 0));
        ((JSpinner.NumberEditor) successPercentageSpinner.getEditor()).getTextField().setEditable(false);
    }
    successPercentageSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            successPercentageSpinnerStateChanged(evt);
        }
    });

    btnSuccessPercentageHelp.setText("?");
    btnSuccessPercentageHelp.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnSuccessPercentageHelpActionPerformed(evt);
        }
    });

    delayTimeLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    delayTimeLabel.setText("Delay time(Before run):");

    delayTimeTextField.setFont(new java.awt.Font("Dialog", 0, 11));
    delayTimeTextField.setText("0");
    delayTimeTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            delayTimeTextFieldActionPerformed(evt);
        }
    });
    delayTimeTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            delayTimeTextFieldFocusLost(evt);
        }
    });

    aSynchCallLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    aSynchCallLabel.setText("Asynch Call * :");

    aSynchCallChoice.add("false");
    if (!(parent.getObject() instanceof PreConditionCaseRefined || parent.getObject() instanceof PostConditionCaseRefined))
    aSynchCallChoice.add("true");
    aSynchCallChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            aSynchCallChoiceItemStateChanged(evt);
        }
    });

    criticalLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    criticalLabel.setText("Critical * :");

    criticalChoice.add("false");
    criticalChoice.add("true");
    criticalChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            criticalChoiceItemStateChanged(evt);
        }
    });

    delayTimeLabel1.setFont(new java.awt.Font("Dialog", 0, 11));
    delayTimeLabel1.setText("Delay time(After run):");

    afterdelayTimeTextField.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
    afterdelayTimeTextField.setText("0");
    afterdelayTimeTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            afterdelayTimeTextFieldActionPerformed(evt);
        }
    });
    afterdelayTimeTextField.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            afterdelayTimeTextFieldFocusLost(evt);
        }
    });

    jLabel1.setText("Store results postfix:");

    javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
        jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel5Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup()
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(delayTimeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                        .addComponent(successPercentageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(dataArrayAppliesToCaseLabel))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel5Layout.createSequentialGroup()
                            .addComponent(successPercentageSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnSuccessPercentageHelp, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(delayTimeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(dataArrayAppliesToCaseChoice, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(8, 8, 8))
                .addGroup(jPanel5Layout.createSequentialGroup()
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(delayTimeLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(criticalLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(aSynchCallLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                        .addComponent(jLabel1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtStoreResultPostfix)
                        .addComponent(criticalChoice, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(aSynchCallChoice, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(afterdelayTimeTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))))
            .addContainerGap())
    );

    jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {aSynchCallLabel, dataArrayAppliesToCaseLabel, delayTimeLabel, successPercentageLabel});

    jPanel5Layout.setVerticalGroup(
        jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel5Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(dataArrayAppliesToCaseChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(dataArrayAppliesToCaseLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(btnSuccessPercentageHelp)
                .addComponent(successPercentageSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(successPercentageLabel))
            .addGap(6, 6, 6)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(delayTimeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(delayTimeLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(delayTimeLabel1)
                .addComponent(afterdelayTimeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(6, 6, 6)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(aSynchCallChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(aSynchCallLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                .addComponent(criticalChoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(criticalLabel))
            .addGap(18, 18, 18)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(txtStoreResultPostfix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap(34, Short.MAX_VALUE))
    );

    // NOT FOR PRECONDITION CASE, POSTCONDITION CASE
    // NOT FOR PRECONDITION CASE, POSTCONDITION CASE
    // NOT FOR PRECONDITION CASE, POSTCONDITION CASE

    jTabbedPane1.addTab("Details", jPanel5);
    jTabbedPane1.addTab("Labels", labelSettingsScrollPane);

    supportedDeviceGroupLabel.setFont(new java.awt.Font("Dialog", 0, 11));
    supportedDeviceGroupLabel.setText("Supported Device Group :");

    supportedDeviceGroupChoice.setEnabled(false);
    supportedDeviceGroupChoice.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            supportedDeviceGroupChoiceItemStateChanged(evt);
        }
    });

    javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
    jPanel8.setLayout(jPanel8Layout);
    jPanel8Layout.setHorizontalGroup(
        jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel8Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(supportedDeviceGroupLabel)
            .addGap(1, 1, 1)
            .addComponent(supportedDeviceGroupChoice, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(338, Short.MAX_VALUE))
    );
    jPanel8Layout.setVerticalGroup(
        jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel8Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(supportedDeviceGroupChoice, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(supportedDeviceGroupLabel))
            .addContainerGap(219, Short.MAX_VALUE))
    );

    jTabbedPane1.addTab("Other", jPanel8);

    saveButton.setText("Save");
    saveButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            saveButtonActionPerformed(evt);
        }
    });

    btnEditLabels.setText("Cancel");
    btnEditLabels.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnEditLabelsActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(saveButton)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(btnEditLabels))
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE))
            .addContainerGap())
    );

    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnEditLabels, saveButton});

    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btnEditLabels)
                .addComponent(saveButton))
            .addContainerGap())
    );

    ConditionsController.createInstance(m_editMode).initialize();
    jTabbedPane1.addTab("Conditions", ConditionsController.getInstance().getConditionView());

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void nameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameTextFieldActionPerformed
        try {
            TestDesignControllerList.newInstance().getTestStepController().
                    operationChangeName(nameTextField.getText());
        } catch (Exception e) {
            //  Handle exception
        }
    }//GEN-LAST:event_nameTextFieldActionPerformed

    private void nameTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFieldFocusLost
        try {
            TestDesignControllerList.newInstance().getTestStepController().
                    operationChangeName(nameTextField.getText());
        } catch (Exception e) {
            //  Handle exception
        }
    }//GEN-LAST:event_nameTextFieldFocusLost

    private void descriptionTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_descriptionTextFieldActionPerformed
        try {
            TestDesignControllerList.newInstance().getTestStepController().
                    operationChangeDescription(descriptionTextField.getText());
        } catch (Exception e) {
            //  Handle exception
        }
}//GEN-LAST:event_descriptionTextFieldActionPerformed

    private void descriptionTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_descriptionTextFieldFocusLost
        try {
            TestDesignControllerList.newInstance().getTestStepController().
                    operationChangeDescription(descriptionTextField.getText());
        } catch (Exception e) {
            //  Handle exception
        }
}//GEN-LAST:event_descriptionTextFieldFocusLost

    private void delayTimeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delayTimeTextFieldActionPerformed

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeDelayTime(delayTimeTextField.getText());
}//GEN-LAST:event_delayTimeTextFieldActionPerformed

    private void delayTimeTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_delayTimeTextFieldFocusLost

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeDelayTime(delayTimeTextField.getText());
}//GEN-LAST:event_delayTimeTextFieldFocusLost

    private void noOfRetryOnFailTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noOfRetryOnFailTextFieldActionPerformed

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeNumberOfRetryOnFail(
                noOfRetryOnFailTextField.getText());
}//GEN-LAST:event_noOfRetryOnFailTextFieldActionPerformed

    private void noOfRetryOnFailTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_noOfRetryOnFailTextFieldFocusLost

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeNumberOfRetryOnFail(
                noOfRetryOnFailTextField.getText());
}//GEN-LAST:event_noOfRetryOnFailTextFieldFocusLost

    private void timeoutTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeoutTextFieldActionPerformed

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeTimeout(timeoutTextField.getText());
}//GEN-LAST:event_timeoutTextFieldActionPerformed

    private void timeoutTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_timeoutTextFieldFocusLost

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeTimeout(timeoutTextField.getText());
}//GEN-LAST:event_timeoutTextFieldFocusLost

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

        WindowListener[] listeners = getWindowListeners();
        for (int i = 0; i < listeners.length; i++) {
            this.removeWindowListener(listeners[i]);
        }
        this.setEnabled(false);
        this.dispose();
        this.invalidate();
        TestDesignControllerList.newInstance().getTestStepController().
                operationCloseWindow();
        ConditionsController.createInstance(m_editMode).operationClose();
    }//GEN-LAST:event_formWindowClosed

    private void supportedDeviceGroupChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_supportedDeviceGroupChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeSupportedDeviceGroup(
                supportedDeviceGroupChoice.getSelectedItem());
}//GEN-LAST:event_supportedDeviceGroupChoiceItemStateChanged

    private void actionChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_actionChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeAction(actionChoice.getSelectedItem());
    }//GEN-LAST:event_actionChoiceItemStateChanged

    private void dataArrayAppliesToCaseChoiceCheckForSuccessPercentageSpinner() {
        if (dataArrayAppliesToCaseChoice.getSelectedItem().equals("true")) {
            successPercentageSpinner.setEnabled(false);
        } else {
            successPercentageSpinner.setEnabled(true);
        }
    }

    private void dataArrayAppliesToCaseChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_dataArrayAppliesToCaseChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeDataArrayAppliesToCase(
                dataArrayAppliesToCaseChoice.getSelectedItem());
}//GEN-LAST:event_dataArrayAppliesToCaseChoiceItemStateChanged

    private void aSynchCallChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_aSynchCallChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeASynchCall(aSynchCallChoice.getSelectedItem());
    }//GEN-LAST:event_aSynchCallChoiceItemStateChanged

    private void criticalChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_criticalChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeCritical(criticalChoice.getSelectedItem());
    }//GEN-LAST:event_criticalChoiceItemStateChanged

    private void modulTypeChoiceCheckForBrowserSpeedSpinner() {
        if (modulTypeChoice.getSelectedItem().equals("WebAutomationModule")) {
        } else {
            browserSpeedSpinner.setEnabled(false);
        }
        browserSpeedSpinner.repaint();
    }

    private void modulTypeChoiceCheckForBrowserTypeChoice() {
        browserTypeChoice.removeAll();
        browserTypeChoice.add("");
        if (modulTypeChoice.getSelectedItem().equals("WebAutomationModule")) {
            browserTypeChoice.setEnabled(true);
            m_choices = TestDesignControllerList.newInstance().
                    getTestStepController().operationGetBrowserTypes();
            for (int i = 0; i < m_choices.length; i++) {
                browserTypeChoice.add(m_choices[i]);
            }
            m_choices = null;
        } else {
            browserTypeChoice.setEnabled(false);
        }
        browserTypeChoice.repaint();
    }

    private void modulTypeChoiceCheckForDeviceChoice() {
        txtDutIp.setEnabled(false);
        if (modulTypeChoice.getSelectedItem().equals(
                "NicModule")) {
            dutLabel.setText("Network Card");
            loadNics();
        } else if (modulTypeChoice.getSelectedItem().equals(
                "WirelessSecurityModule")) {
            dutLabel.setText("Wireless Card");
            loadNics();
        } else if (modulTypeChoice.getSelectedItem().equals(
                "WebAutomationModule")) {
            txtDutIp.setEnabled(true);
            dutLabel.setText("Dut");
            loadDutDevices();
        } else if (modulTypeChoice.getSelectedItem().equals("")) {
            cmbDeviceList.removeAllItems();
            cmbDeviceList.setEnabled(false);
            dutLabel.setText("");
        } else {
            dutLabel.setText("");
        }
        txtDutIp.repaint();
        dutLabel.repaint();
    }

    private void modulTypeChoiceCheckForSupportedDeviceGroupChoice() {
        supportedDeviceGroupChoice.removeAll();
        if (modulTypeChoice.getSelectedItem().equals("WebAutomationModule")) {
            m_choices = TestDesignControllerList.newInstance().
                    getTestStepController().operationGetSupportedDeviceList();
            supportedDeviceGroupChoice.add("");
            for (int i = 0; i < m_choices.length; i++) {
                supportedDeviceGroupChoice.add(m_choices[i]);
            }
            m_choices = null;
            supportedDeviceGroupChoice.setEnabled(true);
        } else {
            supportedDeviceGroupChoice.setEnabled(false);
        }
        supportedDeviceGroupChoice.repaint();
    }

    private void modulTypeChoiceCheckForActionChoice() {
        actionChoice.removeAll();
        if (modulTypeChoice.getSelectedItem().equals("")) {
            actionChoice.setEnabled(false);
        } else {
            m_choices = TestDesignControllerList.newInstance().
                    getTestStepController().operationGetActionList(
                    modulTypeChoice.getSelectedItem());
            for (int i = 0; i < m_choices.length; i++) {
                actionChoice.add(m_choices[i]);
            }
            m_choices = null;

            if (m_editMode && m_selectedNode.hasChildren()) {
                actionChoice.setEnabled(false);
            } else {
                actionChoice.setEnabled(true);
            }
        }
        actionChoice.repaint();
    }

    private void loadNics() {
        cmbDeviceList.removeAllItems();
        cmbDeviceList.addItem("");
        List<NetworkAdapterRefined> nics = TestDesignControllerList.newInstance().
                getTestStepController().operationGetNetworkCardList();
        if (nics != null) {
            if (hNetworkAdapters == null) {
                hNetworkAdapters = new HashMap<Integer, String>();
            } else {
                hNetworkAdapters.clear();
            }
            for (int i = 0; i < nics.size(); i++) {
                hNetworkAdapters.put(nics.get(i).getId(), nics.get(i).getName());
            }
            if (hNetworkAdapters != null) {
                Iterator iter = hNetworkAdapters.entrySet().iterator();
                while (iter.hasNext()) {
                    cmbDeviceList.addItem(new AtofEntryItem(
                            (Map.Entry) iter.next()));
                }
            }
        }
        cmbDeviceList.repaint();
        cmbDeviceList.updateUI();


    }

    private void loadDutDevices() {
        cmbDeviceList.removeAllItems();
        cmbDeviceList.addItem("");
        List<DutRefined> duts = TestDesignControllerList.newInstance().
                getTestStepController().operationGetDutList();
        if (duts != null) {
            if (hDuts == null) {
                hDuts = new HashMap<Integer, String>();
            } else {
                hDuts.clear();
            }
            for (int i = 0; i < duts.size(); i++) {
                hDuts.put(duts.get(i).getId(), duts.get(i).getName());
            }
            if (hDuts != null) {
                Iterator iter = hDuts.entrySet().iterator();
                while (iter.hasNext()) {
                    cmbDeviceList.addItem(new AtofEntryItem(
                            (Map.Entry) iter.next()));
                }
            }
        }
        cmbDeviceList.repaint();
        cmbDeviceList.updateUI();


    }

    private void loadPcs() {
        cmbPcList.removeAllItems();
        cmbPcList.addItem("");
        List<TestPcRefined> pcs = TestDesignControllerList.newInstance().
                getTestStepController().operationGetPcList();
        if (pcs != null) {
            if (hTestPcs == null) {
                hTestPcs = new HashMap<Integer, String>();
            } else {
                hTestPcs.clear();
            }
            for (int i = 0; i < pcs.size(); i++) {
                hTestPcs.put(pcs.get(i).getId(), pcs.get(i).getName());
            }
            if (hTestPcs != null) {
                Iterator iter = hTestPcs.entrySet().
                        iterator();
                while (iter.hasNext()) {
                    cmbPcList.addItem(new AtofEntryItem((Map.Entry) iter.next()));
                }
            }
        }
        cmbPcList.repaint();
        cmbPcList.updateUI();
    }

    private void modulTypeChoice() {
        modulTypeChoiceCheckForActionChoice();
        modulTypeChoiceCheckForSupportedDeviceGroupChoice();
        modulTypeChoiceCheckForBrowserSpeedSpinner();
        modulTypeChoiceCheckForBrowserTypeChoice();
        loadPcs();
        modulTypeChoiceCheckForDeviceChoice();
    }

    private void modulTypeChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_modulTypeChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeModulType(modulTypeChoice.getSelectedItem());
        modulTypeChoice();

    }//GEN-LAST:event_modulTypeChoiceItemStateChanged

    private void browserTypeChoiceItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_browserTypeChoiceItemStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeBrowserType(browserTypeChoice.getSelectedItem());
        browserTypeChoiceCheckBrowserSpeedSpinner();
    }//GEN-LAST:event_browserTypeChoiceItemStateChanged

    private void browserTypeChoiceCheckBrowserSpeedSpinner() {
        if (browserTypeChoice.getSelectedItem() != null && !browserTypeChoice.getSelectedItem().
                equals("")) {
            browserSpeedSpinner.setEnabled(true);
        } else {
            browserSpeedSpinner.setEnabled(false);
        }
        browserSpeedSpinner.updateUI();
    }

    private void successPercentageSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_successPercentageSpinnerStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeSuccessPercentage(((JSpinner.NumberEditor) successPercentageSpinner.getEditor()).getTextField().
                getText());
    }//GEN-LAST:event_successPercentageSpinnerStateChanged

    private void browserSpeedSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_browserSpeedSpinnerStateChanged

        TestDesignControllerList.newInstance().getTestStepController().
                operationChangeBrowserSpeed(((JSpinner.NumberEditor) browserSpeedSpinner.getEditor()).getTextField().
                getText());
    }//GEN-LAST:event_browserSpeedSpinnerStateChanged

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        if (!TestDesignControllerList.newInstance().getTestStepController().
                checkConstraints()) {
            return;
        }
        if (!validateForm()) {
            return;
        }

        saveButton.setEnabled(false);
        String supportedDeviceGroup =
                supportedDeviceGroupChoice.getSelectedItem();
        if (supportedDeviceGroup == null) {
            supportedDeviceGroup = "";
        }

        HashMap<String, Object> params = new HashMap<String, Object>();
        if (cmbPcList.getSelectedItem() != null && !cmbPcList.getSelectedItem().
                toString().equals("")) {
            Entry entry = (Entry) cmbPcList.getSelectedItem();
            if (entry.getKey() != null) {
                params.put("pc",
                        entry.getKey().toString());
            }
        }
        if (modulTypeChoice.getSelectedItem().equals(
                "NicModule") || modulTypeChoice.getSelectedItem().equals(
                "WirelessSecurityModule")) {
            if (cmbDeviceList.getSelectedItem() != null && !cmbDeviceList.getSelectedItem().
                    toString().equals("")) {
                Entry entry = (Entry) cmbDeviceList.getSelectedItem();
                if (entry.getKey() != null) {
                    params.put("nic", entry.getKey().toString());
                }
            }
        } else {
            if (cmbDeviceList.getSelectedItem() != null && !cmbDeviceList.getSelectedItem().
                    toString().equals("")) {
                Entry entry = (Entry) cmbDeviceList.getSelectedItem();
                if (entry.getKey() != null) {
                    params.put("dut", entry.getKey().toString());
                }
            }
        }
        params.put("name", nameTextField.getText());
        params.put("description", descriptionTextField.getText());
        params.put("storeResultPostfix", txtStoreResultPostfix.getText().trim());
        params.put("aSynchCall", aSynchCallChoice.getSelectedItem());
        params.put("browserSpeed",
                ((JSpinner.NumberEditor) browserSpeedSpinner.getEditor()).getTextField().getText());
        params.put("browserType", "*" + browserTypeChoice.getSelectedItem());
        params.put("critical", criticalChoice.getSelectedItem());
        params.put("dataArrayAppliesToCase",
                dataArrayAppliesToCaseChoice.getSelectedItem());
        params.put("delayTime", delayTimeTextField.getText());
        params.put("afterDelayTime", afterdelayTimeTextField.getText());

        if (txtDutIp.getText() != null && !txtDutIp.getText().equals("")) {
            params.put("deviceIp", txtDutIp.getText());
        }
        params.put("noOfRetryOnFail", noOfRetryOnFailTextField.getText());

        params.put("successPercentage",
                ((JSpinner.NumberEditor) successPercentageSpinner.getEditor()).getTextField().getText());
        params.put("supportedDeviceGroup", supportedDeviceGroup);
        params.put("timeout", timeoutTextField.getText());

        LinkedList<String> labels = m_labelSettingsView.getSelectedLabelNames();
        params.put("labels", labels);

        LinkedHashMap<Integer, String> listOfCond = ConditionsController.getInstance().getConditionsList();

        if (listOfCond != null) {
            params.put("conditions", listOfCond);
        }

        if (m_editMode) {
            if (!m_selectedNode.hasChildren()) {
                params.put("action",
                        actionChoice.getSelectedItem());
                params.put("modulType",
                        modulTypeChoice.getSelectedItem());
            }
            TestDesignControllerList.newInstance().getTestStepController().
                    operationSaveTestStep(params);
        } else {
            params.put("action",
                    actionChoice.getSelectedItem());
            params.put("modulType",
                    modulTypeChoice.getSelectedItem());
            try {
                TestDesignControllerList.newInstance().getTestStepController().operationAddTestStep(
                        params);
            } catch (PersistentException ex) {
                ex.printStackTrace();
            }
        }
        this.dispose();
    }//GEN-LAST:event_saveButtonActionPerformed

private void btnSuccessPercentageHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuccessPercentageHelpActionPerformed
    JOptionPane.showMessageDialog(null,
            " if the TestStep is not marked as DataArrayAppliesToCase then TestStep"
            + " \n Success Percentage will be used otherwise Test Case’s Success Percentage"
            + " \n will be a measure. ",
            "Information",
            JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_btnSuccessPercentageHelpActionPerformed

private void btnEditLabelsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditLabelsActionPerformed
    this.dispose();
}//GEN-LAST:event_btnEditLabelsActionPerformed

private void afterdelayTimeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_afterdelayTimeTextFieldActionPerformed
    TestDesignControllerList.newInstance().getTestStepController().
            operationChangeAfterDelayTime(afterdelayTimeTextField.getText());
}//GEN-LAST:event_afterdelayTimeTextFieldActionPerformed

private void afterdelayTimeTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afterdelayTimeTextFieldFocusLost
    TestDesignControllerList.newInstance().getTestStepController().
            operationChangeAfterDelayTime(afterdelayTimeTextField.getText());
}//GEN-LAST:event_afterdelayTimeTextFieldFocusLost

private void cmbPcListİtemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbPcListİtemStateChanged
    Integer pcId = 0;
    if (cmbPcList.getSelectedItem() != null && !cmbPcList.getSelectedItem().
            toString().equals("")) {
        Entry entry = (Entry) cmbPcList.getSelectedItem();
        pcId = Integer.parseInt(entry.getKey().toString());
    }
    if (pcId != curPcId) {
        curPcId = pcId;
        TestDesignControllerList.newInstance().getTestStepController().
                operationChangePc(pcId);
    }
}//GEN-LAST:event_cmbPcListİtemStateChanged

private void cmbDeviceListİtemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbDeviceListİtemStateChanged
    Integer deviceId = 0;
    if (cmbDeviceList.getSelectedItem() != null && !cmbDeviceList.getSelectedItem().
            toString().equals("")) {
        Entry entry = (Entry) cmbDeviceList.getSelectedItem();
        deviceId = Integer.parseInt(entry.getKey().toString());
    }
    TestDesignControllerList.newInstance().getTestStepController().
            operationChangeDevice(deviceId);
}//GEN-LAST:event_cmbDeviceListİtemStateChanged
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                TestPlanView dialog = new TestPlanView(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Choice aSynchCallChoice;
    private javax.swing.JLabel aSynchCallLabel;
    private java.awt.Choice actionChoice;
    private javax.swing.JLabel actionLabel;
    private javax.swing.JTextField afterdelayTimeTextField;
    private javax.swing.JLabel browserSpeedLabel;
    private javax.swing.JSpinner browserSpeedSpinner;
    private java.awt.Choice browserTypeChoice;
    private javax.swing.JLabel browserTypeLabel;
    private javax.swing.JButton btnEditLabels;
    private javax.swing.JButton btnSuccessPercentageHelp;
    private javax.swing.JComboBox cmbDeviceList;
    private javax.swing.JComboBox cmbPcList;
    private java.awt.Choice criticalChoice;
    private javax.swing.JLabel criticalLabel;
    private java.awt.Choice dataArrayAppliesToCaseChoice;
    private javax.swing.JLabel dataArrayAppliesToCaseLabel;
    private javax.swing.JLabel delayTimeLabel;
    private javax.swing.JLabel delayTimeLabel1;
    private javax.swing.JTextField delayTimeTextField;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JTextField descriptionTextField;
    private javax.swing.JLabel dutLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JTabbedPane jTabbedPane1;
    private java.awt.Label label1;
    private javax.swing.JScrollPane labelSettingsScrollPane;
    private java.awt.Choice modulTypeChoice;
    private javax.swing.JLabel modulTypeLabel;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JLabel noOfRetryOnFailLabel;
    private javax.swing.JTextField noOfRetryOnFailTextField;
    private javax.swing.JLabel pcLabel;
    private javax.swing.JButton saveButton;
    private javax.swing.JLabel successPercentageLabel;
    private javax.swing.JSpinner successPercentageSpinner;
    private java.awt.Choice supportedDeviceGroupChoice;
    private javax.swing.JLabel supportedDeviceGroupLabel;
    private javax.swing.JLabel timeoutLabel;
    private javax.swing.JTextField timeoutTextField;
    private javax.swing.JTextField txtDutIp;
    private javax.swing.JTextField txtStoreResultPostfix;
    // End of variables declaration//GEN-END:variables

    @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        //System.out.println(this.getClass() + evt.getPropertyName());
        if (evt.getPropertyName().equals(TestStepController.SHOW_ADD_TEST_STEP)) {
            this.centerParent();
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_NAME)) {
            nameTextField.setText((String) evt.getNewValue());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_DESCRIPTION)) {
            descriptionTextField.setText((String) evt.getNewValue());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_SUPPORTED_DEVICE_GROUP)) {
            supportedDeviceGroupChoice.select((String) evt.getNewValue());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_ACTION)) {
            actionChoice.select((String) evt.getNewValue());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_DATA_ARRAY_APPLIES_TO_CASE)) {
            Boolean newChoice = (Boolean) evt.getNewValue();
            dataArrayAppliesToCaseChoice.select(newChoice.toString());
            dataArrayAppliesToCaseChoiceCheckForSuccessPercentageSpinner();
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_DELAY_TIME)) {
            delayTimeTextField.setText("" + (Integer) evt.getNewValue());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_AFTER_DELAY_TIME)) {
            afterdelayTimeTextField.setText("" + (Integer) evt.getNewValue());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_STORE_RESULT_POSTFIX)) {
            txtStoreResultPostfix.setText((String)evt.getNewValue());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_LAST_WARNING)) {
            String warnMsg = (String) evt.getNewValue();
            JOptionPane.showMessageDialog(null,
                    warnMsg,
                    "Warning",
                    JOptionPane.WARNING_MESSAGE);
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_ASYNCH_CALL)) {
            Boolean newResult = (Boolean) evt.getNewValue();
            aSynchCallChoice.select((newResult).toString());
            if (newResult == true) {
                noOfRetryOnFailTextField.setEnabled(false);
            } else {
                noOfRetryOnFailTextField.setEnabled(true);
            }
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_NUMBER_OF_RETRY_ON_FAIL)) {
            noOfRetryOnFailTextField.setText(
                    ((Integer) evt.getNewValue()).toString());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_CRITICAL)) {
            criticalChoice.select(((Boolean) evt.getNewValue()).toString());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_SUCCESS_PERCENTAGE)) {
            ((JSpinner.NumberEditor) successPercentageSpinner.getEditor()).getTextField().setText(
                    ((Byte) evt.getNewValue()).toString());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_TIMEOUT)) {
            timeoutTextField.setText(((Integer) evt.getNewValue()).toString());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_MODULE_TYPE)) {
            String newValue = (String) evt.getNewValue();
            if (m_editMode) {
                modulTypeChoice.add(newValue);
                modulTypeChoice.select(newValue);
            } else {
                modulTypeChoice.select(newValue);
            }
            modulTypeChoice();
        } else if (evt.getPropertyName().equals(TestStepController.CHANGE_PC)) {
            Object key = evt.getNewValue();
            Iterator iter = hTestPcs.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                if (entry.getKey().toString().equals(key.toString())) {
                    cmbPcList.setSelectedItem(entry);
                    break;
                }
            }
            modulTypeChoiceCheckForDeviceChoice();
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_BROWSER_SPEED)) {
            ((JSpinner.NumberEditor) browserSpeedSpinner.getEditor()).getTextField().setText(
                    evt.getNewValue().toString());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_BROWSER_TYPE)) {
            browserTypeChoice.select(evt.getNewValue().toString().substring(1));
            browserTypeChoiceCheckBrowserSpeedSpinner();
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_DUT_IP)) {
            txtDutIp.setText((String) evt.getNewValue());
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_DEVICE)) {
            Object key = evt.getNewValue();
            if (dutLabel.getText().equals("Dut")) {
                Iterator iter = hDuts.entrySet().iterator();
                while (iter.hasNext()) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    if (entry.getKey().toString().equals(key.toString())) {
                        cmbDeviceList.setSelectedItem(entry);
                        break;
                    }
                }
            } else if (cmbDeviceList.isEnabled()) {
                Iterator iter = hNetworkAdapters.entrySet().iterator();
                while (iter.hasNext()) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    if (entry.getKey().toString().equals(key.toString())) {
                        cmbDeviceList.setSelectedItem(entry);
                        break;
                    }
                }
            }
        } else if (evt.getPropertyName().equals(
                TestStepController.CHANGE_TIMEOUT)) {
            timeoutTextField.setText((String) evt.getNewValue());
        }
    }

    @Override
    public boolean validateForm() {
        boolean valid = true;
        StringBuilder builder = new StringBuilder();
        if (ValidationUtils.isEmpty(nameTextField.getText())) {
            builder.append("Name must not be empty.\n");
            valid = false;
        }
        if (ValidationUtils.isEmpty(modulTypeChoice.getSelectedItem())) {
            builder.append("You must choose a modulType!\n");
            valid = false;
        }
        if (ValidationUtils.isEmpty(actionChoice.getSelectedItem())) {
            builder.append("You must choose an Action!\n");
            valid = false;
        }
        if (ValidationUtils.isEmpty(delayTimeTextField.getText())) {
            builder.append("Delay time must not be empty.\n");
            valid = false;
        } else if (!ValidationUtils.isNumeric(delayTimeTextField.getText())) {
            builder.append("Delay time(Before Run) must be numeric.\n");
            valid = false;
        } else if (!ValidationUtils.isNumeric(
                afterdelayTimeTextField.getText())) {
            builder.append("Delay time(After Run) must be numeric.\n");
            valid = false;
        } else if (!ValidationUtils.isNumeric(
                noOfRetryOnFailTextField.getText())) {
            builder.append("Number of Retry on Fail must be numeric.\n");
            valid = false;
        }
        if (!txtDutIp.isEnabled()) {
            txtDutIp.setText("");
        }

        if (aSynchCallChoice.getSelectedItem().equals("false")) {
            if (ValidationUtils.isEmpty(noOfRetryOnFailTextField.getText())) {
                builder.append(
                        "In Steps with AsynchCall disabled, \"No retry on fail\" must not be empty.\n");
                valid = false;
            } else if (!ValidationUtils.isNumeric(
                    noOfRetryOnFailTextField.getText())) {
                builder.append("No retry on fail must  be numeric.\n");
                valid = false;
            }
        }

        if (ValidationUtils.isEmpty(timeoutTextField.getText())) {
            builder.append("Timeout must not be empty.\n");
            valid = false;
        } else if (!ValidationUtils.isNumeric(timeoutTextField.getText())) {
            builder.append("Timeout must be numeric.\n");

            valid = false;
        }
        if (!valid) {
            JOptionPane.showMessageDialog(null,
                    builder.toString(),
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
        return valid;
    }
}
